package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.controller.utils.A;
import com.example.dao.BookDao;
import com.example.domain.Book;
import com.example.service.MsgService;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class MsgServiceImpl extends ServiceImpl<BookDao, Book> implements MsgService {

    private HashMap<String, String> cache = new HashMap<>();

    @Override
    public A get(String tele) {
        if (tele.length() < 11) {
            return new A(false, null, "请输入正确的手机号码");
        } else {
            String code = tele.substring(tele.length() - 6);
            cache.put(tele, code);
            return new A(true, code, "操作成功");
        }
    }

    @Override
    public A check(String tele, String code) {
        String queryCode = cache.get(tele);
        if (code.equals(queryCode)) {
            return new A(true, "验证成功");
        }else {
            return new A(false, "验证失败");
        }
    }
}